<!doctype html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security" xmlns:auth=""
>
<auth:data uri="/system/job/userJob.json"/>

<head>
    <th:block th:include="common/head::noXadmin('添加用户')"/>
</head>
<body class="layui-layout layui-layout-admin">
<div class="layui-container">
    <form class="layui-form " th:action="@{/system/user/edit}" method="post">
        <input type="hidden" id="userId" name="userId" th:value="${user?.userId}"/>
        <fieldset class="layui-elem-field layui-field-title">
            <legend>基本信息</legend>
        </fieldset>
        <div class="layui-row layui-col-space30 " style="margin: 0px 30px 0px 30px ">
            <div class="layui-col-md6">
                <div class="layui-form-item">
                    <label class="layui-form-label">登录账号</label>
                    <div class="layui-input-block">
                        <input type="text" name="username" autocomplete="off" placeholder="请输入登录账号" class="layui-input"
                               required lay-verify="required|username" th:value="${user?.username}" disabled>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">用户姓名</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" autocomplete="off" lay-verify="required" placeholder="请输入用户姓名"
                               class="layui-input" th:value="${user?.name}" disabled>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">手机号</label>
                    <div class="layui-input-block">
                        <input type="text" name="mobile" lay-verify="required|phone" placeholder="请输入手机号"
                               autocomplete="off"
                               class="layui-input" th:value="${user?.mobile}" disabled>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">邮箱</label>
                    <div class="layui-input-block">
                        <input type="text" name="email" placeholder="邮箱" autocomplete="off"
                               class="layui-input" lay-verify="required|email" th:value="${user?.email}" disabled>
                    </div>
                </div>

            </div>
            <div class="layui-col-md6 ">

                <div class="layui-form-item ">
                    <label class="layui-form-label is-required">部门</label>
                    <div class="layui-input-block">
                        <input type="hidden" id="deptId" name="deptId" th:value="${dept?.deptId}">
                        <input type="text" id="deptName" placeholder="请选择部门" class="layui-input"
                               th:value="${dept?.deptName}" lay-verify="required" readonly>
                    </div>
                </div>
                <div class="layui-form-item ">
                    <label class="layui-form-label is-required">岗位</label>
                    <div class="layui-input-block">
                        <div id="job" class="xm-select-demo"></div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">性别</label>
                    <div class="layui-input-block">
                        <input type="radio" name="sex" value="F" title="男" th:checked="${user?.sex eq 'F'}" disabled>
                        <input type="radio" name="sex" value="M" title="女" th:checked="${user?.sex eq 'M'}" disabled>
                    </div>
                </div>
                <div class="layui-form-item" pane="">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <input type="checkbox" checked name="status" lay-skin="switch" lay-filter="status"
                               lay-text="启用|停用" value="0" th:checked="${user?.status eq 0}" disabled>
                    </div>
                </div>


            </div>
        </div>

        <fieldset class="layui-elem-field layui-field-title">
            <legend>其他信息</legend>
        </fieldset>
        <div class="layui-row" style="margin: 0px 30px 0px 30px ">
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入内容" class="layui-textarea" name="remark"
                              th:text="${user?.remark}" disabled></textarea>
                </div>
            </div>
        </div>

    </form>
</div>
<script>
    layui.use(['form', 'layedit', 'laydate', 'xmSelect'], function () {
        let form = layui.form
            , layer = layui.layer;
        form.render();
        let job = xmSelect.render({
            el: '#job',
            toolbar: {show: false},
            name: "jobIds",
            filterable: true,
            disabled: true,
            data: []
        });
        $.ajax({
            url: rootPath + 'system/job/userJob.json?userId=' + $("#userId").val(),
            type: "GET",
            dataType: "json",
            success: function (res) {
                let d = res.data,
                    d2 = [];
                for (let i = 0; i < d.length; i++) {
                    d2[i] = {};
                    d2[i]['name'] = d[i].jobName;
                    d2[i]['value'] = d[i].jobId;
                    d2[i]['selected'] = d[i]['checked'] ? true : false;
                }
                job.update({
                    data: d2,
                    autoRow: true
                })
            },
            error: function (data) {
                layer.msg(data.message);
            }
        });
    })
</script>

</body>

</html>
